package xyz.kail.demo.consul.api.catalog;

import com.ecwid.consul.v1.ConsulRawClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.catalog.CatalogConsulClient;
import com.ecwid.consul.v1.catalog.model.CatalogService;
import com.ecwid.consul.v1.catalog.model.Node;
import xyz.kail.demo.consul.api.R;

import java.util.List;
import java.util.Map;

/**
 * Created by kail on 2018/1/21.
 */
public class ConsulCatalogMain {

    public static void main(String[] args) {
        ConsulRawClient consulRawClient = new ConsulRawClient(R.IP, R.PORT);
        CatalogConsulClient catalogConsulClient = new CatalogConsulClient(consulRawClient);

        Response<List<String>> datacenters = catalogConsulClient.getCatalogDatacenters();
        System.out.println(datacenters);
        System.out.println();


        Response<List<Node>> catalogNodes = catalogConsulClient.getCatalogNodes(QueryParams.DEFAULT);
        System.out.println(catalogNodes);
        System.out.println();


        Response<Map<String, List<String>>> catalogServices = catalogConsulClient.getCatalogServices(QueryParams.DEFAULT);
        System.out.println(catalogServices);
        System.out.println();


        Response<List<CatalogService>> catalogService = catalogConsulClient.getCatalogService("consul-provider", QueryParams.DEFAULT);
        System.out.println(catalogService);
        List<CatalogService> catalogServiceValue = catalogService.getValue();
        for (CatalogService service : catalogServiceValue) {
            System.out.println(service.getServiceId());
        }
        System.out.println();


    }


}
